home *** CD-ROM | disk | FTP | other *** search
/ SunSoft Catalyst CDWARE 1996 May to August / Catalyst CDWARE 1996 May to August.iso / .products / .bin / httpd / Solaris_2 / tclsh < prev    next >
Text File  |  1995-12-04  |  12KB  |  428 lines

  1. #!/bin/sh
  2. #
  3. #  @(#)  .cam,v1.4_wrapper      1.1    Last mod: 17 Oct 1995
  4. #
  5. # Authors: SoftDist Central (softdist@softdist)
  6. #
  7. # Description:
  8. #     This is a wrapper for implementing configuration-appropriate command
  9. #         execution for CAM 
  10. # NOTE : This version has special handling for announce function
  11. #
  12. # Environment:
  13. #     CAM_HOME    Base directory location
  14. #     LD_LIBRARY_PATH
  15. #
  16.  
  17. ##
  18. # Define DIST_HOME
  19. ##
  20.  
  21. # Honor variable UDHOME for transitional support of Engineering environments.
  22. DIST_HOME=${UDHOME:-$DIST_HOME}
  23. DIST_HOME=${DIST_HOME:-/usr/dist}
  24. SAVED_PATH=$PATH
  25. PATH=/bin
  26.  
  27. ##
  28. # Variable Definition Block
  29. ##
  30. Environment()
  31. {
  32. if [ -x /bin/uname ];then
  33. export os hostname arch major_os
  34. set `/bin/uname -nrm` 2>&-
  35. hostname=$1
  36. os=$2
  37. arch=`/bin/expr $3 : '\(sun[0-9]*\)' \| $3`
  38. major_os=`/bin/expr $os : '\(.\)'`
  39. return 0
  40. else
  41. return 1
  42. fi
  43. }
  44.  
  45.  
  46. export CAM_HOME DIST_HOME SAVE_LD_LIB LD_LIBRARY_PATH NEWS
  47. productname=cam
  48. version=1.4
  49. package=$productname,v$version
  50. #    Version_handler ${1+"$@"}
  51. if Environment; then
  52. :
  53. else
  54. [ $_Arch_loaded ] || {
  55. Arch () {
  56.     case $1 in
  57.         '') /bin/arch $* 2>&- || {
  58.                 set `/bin/uname -m`
  59.                 /bin/expr $1 : '\(sun[0-9]*\)' \| $1
  60.             }
  61.             ;;
  62.         -k) /bin/arch $* 2>&- || /bin/uname -m ;;
  63.          *) if [ -x /bin/arch ]; then
  64.                 /bin/arch $*
  65.             else
  66.                 set $1 `/bin/uname -m`
  67.                 [ $1 = `/bin/expr $2 : '\(sun[0-9]*\)' \| $2` ]
  68.             fi ;;
  69.     esac
  70. }
  71. _Arch_loaded=1
  72. }
  73.  
  74. [ $_Osr_loaded ] || {
  75. Osr () {
  76.     /bin/expr `
  77.         {
  78.             /bin/uname -r ||
  79.             /bin/cat /usr/sys/conf*/RELEASE
  80.         } 2>&- ||
  81.         /etc/dmesg |
  82.         /bin/awk '
  83.             BEGIN { status = 1 }
  84.             /^SunOS Release/ { print $3; status = 0; exit }
  85.             END { exit status }
  86.         ' ||
  87.         /bin/expr "\`
  88.             /usr/ucb/strings -50 /vmunix |
  89.             /bin/egrep '^SunOS Release'
  90.         \`" : 'SunOS Release \([^ ]*\)'
  91.     ` : '\([.0-9]*\)'
  92. }
  93.  
  94. _Osr_loaded=1
  95. }
  96.  
  97. os=`Osr`
  98. arch=`Arch`
  99. hostname=`/bin/hostname 2>&- || /bin/uname -n`
  100. export os hostname arch major_os
  101. fi
  102. #
  103. CAM_HOME=$DIST_HOME/pkgs/$package
  104. command=$CAM_HOME/${major_os}bin.$arch/cam
  105. cmdname=`basename $0`
  106. if [ `/bin/echo $* | /bin/grep -c ",debug" ` -eq 0 ]; then
  107.     opt=",silent"
  108. else
  109.    opt=
  110. fi
  111.  
  112. ##
  113. # Application Prerequisite Block
  114. ##
  115.  
  116. if [ "$REMHOST" ]; then
  117.   REMHOST_S5X=$REMHOST
  118.   export REMHOST_S5X
  119. fi
  120.  
  121. #
  122. # Check Architecture Requirement
  123. #
  124.  
  125. #
  126. # Check Operating System Version Requirement
  127. #
  128.  
  129. #
  130. # Check Window System Requirement 
  131. #
  132. _ow_display=`/bin/expr "$*"  : '.*-display *\([^:]*:[^ ]*\)'`
  133. if [ -z "$OPENWINHOME" -o -z "$DISPLAY" ];then
  134. [ $_Ow_loaded ] || {
  135.  
  136. # Function:
  137. #     @(#)ow                       (Wayne.Thompson@Sun.COM) 05/15/92
  138. #
  139. # Description:
  140. #     This function returns true if invoked from within the OpenWindows
  141. #     environment and server permission is true, otherwise false.
  142. #     If the following environment variables are NOT set 
  143. #     they will be set to the default values:
  144. #         $DISPLAY
  145. #         $LD_LIBRARY_PATH
  146. #         $OPENWINHOME
  147. #      If they are set, they will NOT be modified.
  148. #
  149. # Variables:
  150. #     DIST_HOME         Assumes set from wrapper
  151. #     OPENWINHOME       root of OpenWindows hierarchy.
  152. #     LD_LIBRARY_PATH   shared libraries directory(s).
  153. #     DISPLAY           current xnews server/display.
  154. #     arch              current application architecture.
  155. #     owvers            OpenWindows version.
  156. #     sockets           available Xwindow server sockets.
  157. #
  158. # Usage:
  159. #     Ow
  160. #
  161. # Return:
  162. #     0         OpenWindows is true, server permission is true.
  163. #     1         OpenWindows is true, server permission is false.
  164. #     2         OpenWindows likely true, $DISPLAY is incorrect.
  165. #                   $sockets set to /tmp/.X11-unix/X?
  166. #     3         OpenWindows is true, server socket has been removed.
  167. #     4         OpenWindows is false.
  168. #
  169. # Dependencies:
  170. #
  171. #     OPENWINHOME fall-thru case is SunOS4.x dependent (ps(1)).
  172. #     OPENWINHOME default case is "$DIST_HOME/pkgs/openwin".
  173. #
  174. # Bugs:
  175. #     $LD_LIBRARY_PATH set to wrong version of OW not compensated.
  176.  
  177. ##
  178. # Function Load Block
  179. ##
  180.  
  181.  
  182.  
  183. Ow () {
  184.     export OPENWINHOME   
  185.     [ $OPENWINHOME ] || {
  186.         ## OPENWINHOME is not set, set it to something reasonable
  187.         [ $_OPENWINHOME ] && __OPENWINHOME=$_OPENWINHOME
  188.         if [ ! -x $__OPENWINHOME/bin/xhost ]; then
  189.        case $major_os in
  190.           4) __OPENWINHOME=$DIST_HOME/share/openwin,v3.0
  191.               ;;
  192.               5) __OPENWINHOME=/usr/openwin
  193.           ;;
  194.        esac
  195.         fi
  196.     if [ -x $__OPENWINHOME/bin/xhost ]; then
  197.            OPENWINHOME=$__OPENWINHOME
  198.         else
  199.                [ $_DISTENV ] || {
  200.                   ( . $HOME/.dist/.distrc 2>&- ) &&
  201.                     . $HOME/.dist/.distrc
  202.             }
  203.  
  204.         OPENWINHOME=`
  205.                 /bin/echo $_DISTENV |
  206.                 /bin/awk '
  207.                     BEGIN {
  208.                         FS = "|";
  209.                         status = 1;
  210.                     }
  211.  
  212.                     {
  213.                         for (i = 1; i <= NF; i++) {
  214.                             if ($i == "OpenWin,v3.0") {
  215.                                 print "'$DIST_HOME'/pkgs/openwin,v3.0";
  216.                                 status = 0;
  217.                                 exit;
  218.                             }
  219.                             if ($i == "OpenWin,v2.0") {
  220.                                 print "'$DIST_HOME'/'${arch:-\`Arch\`}'/openwin,v2.0";
  221.                                 status = 0;
  222.                                 exit;
  223.                             }
  224.                             if ($i ~ /^(SunView|SunDesk|DeskSet)/) {
  225.                                 print "SunView";
  226.                                 status = 0;
  227.                                 exit;
  228.                             }
  229.                         }
  230.                     }
  231.  
  232.                     END { exit status }
  233.                 ' ||
  234.                 /bin/ps ewwtco 2>&- |
  235.                 /bin/awk '
  236.                     BEGIN { status = 1 }
  237.  
  238.                     /OPENWINHOME/ {
  239.                         for (i = 6; i <= NF; i++) {
  240.                             split($i, x, "=");
  241.                             if (x[1] == "OPENWINHOME") {
  242.                                 print x[2];
  243.                                 status = 0;
  244.                                 exit;
  245.                             }
  246.                         }
  247.                     }
  248.  
  249.                     END { exit status }
  250.                 ' || {
  251.                     [ -x /opt/openwin/bin/xhost ] &&
  252.                     /bin/echo /opt/openwin
  253.                 } ||
  254.                 if [ -x /usr/openwin/bin/xhost ]; then
  255.                     /bin/echo /usr/openwin
  256.                 else
  257.                     /bin/echo $DIST_HOME/pkgs/openwin
  258.                 fi
  259.             `
  260.  
  261.     fi
  262.     }
  263.     [ ${DISPLAY:=$_ow_display} ] || {
  264.         ## DISPLAY is not set, set it to something reasonable
  265.         _=`
  266.             _=\`/bin/expr "\\\`/bin/who am i 2>&-\\\`" : '.*(\([^.)]*\.*[^.)]*\)'\`
  267.             {
  268.                 NIS_PATH=${NIS_PATH:-org_dir.\$:\$} \
  269.                 /bin/nismatch $_ hosts 2>&- ||
  270.                 /bin/ypmatch $_ hosts 2>&-
  271.             } |
  272.             /bin/awk '{ print $2; exit }'
  273.         `
  274.         if [ $_ ]; then
  275.             DISPLAY=$_:0
  276.             export DISPLAY
  277.         #else
  278.         #    DISPLAY=:0.0
  279.         fi
  280.     }
  281. }
  282.  
  283. _Ow_loaded=1
  284. }
  285. Ow
  286. fi
  287.  
  288. # check if arch is i86pc
  289. if [ "$arch" = "i86pc"  -a -z "`/bin/grep  $cmdname $DIST_HOME/exe/i86pc 2>/dev/null`" -o "$arch" = "prep" ]; then
  290.  
  291. Remhost()
  292. {
  293.     export OPENWINHOME DISPLAY LD_LIBRARY_PATH REMOTE
  294.     if [ "$major_os" = "4" ]; then
  295.       RSH=/usr/ucb/rsh
  296.     else
  297.      RSH=/bin/rsh
  298.     fi
  299.     cmdname=`/bin/basename $0`
  300.     if [ "$REMHOST" ]; then
  301.        whoami=`who am i|/bin/awk '{print $1}'`
  302.        if $RSH -n $REMHOST "/bin/grep root /etc/passwd" >/dev/null 2>&1
  303.        then
  304.     # Even if DISPLAY isn't set, try to do something reasonable
  305.         display_num=`/bin/echo $DISPLAY|/bin/awk -F: '{print $2}'`
  306.     display_num=${display_num:-0.0}
  307.     display_num=":${display_num}"
  308.     display_host=`/bin/echo $DISPLAY|/bin/awk -F: '{print $1}'`
  309.         [ "$display_host" = "unix" ] && display_host=
  310.     display_host=${display_host:-$hostname}
  311.         OPENWINHOME=/usr/openwin; export OPENWINHOME
  312.         ${OPENWINHOME}/bin/xhost -display $display_host +$REMHOST >/dev/null 2>&1
  313.  
  314.     /bin/echo >&2 "Adding host $REMHOST to access list"
  315.     /bin/echo >&2 "Remotely executing $cmdname on host ${REMHOST}"
  316.  
  317.         REMPATH=`/bin/echo ${PATH} | /bin/sed -e "s:${DIST_HOME}:/usr/dist:g"`
  318.         REMCOMMAND="${REMCOMMAND} `/bin/echo $0 |
  319.               /bin/sed -e \"s:${DIST_HOME}:/usr/dist:g\"`"
  320.         REMCOMMAND=/usr/dist/exe/$cmdname
  321.     # If REMWINDOW is "y", then we either have an app that expects the user
  322.     # to be able to type at it once it's invoked (CONCEPT!), or we have
  323.     # an app like FOCUS, which makes bad assumptions about its environment.
  324.  
  325.     if [ "$REMWINDOW" = y ]; then
  326.         /bin/echo "DISPLAY=$display_host$display_num
  327.         TERM=$TERM
  328.         PATH=$REMPATH
  329.                 DIST_HOME=\${DIST_HOME:-/usr/dist}
  330.                 export DIST_HOME
  331.         WRAPPER_FUNCTIONS=\${WRAPPER_FUNCTIONS:-\$DIST_HOME/pkgs/wrapper_funcs/sh}
  332.         export WRAPPER_FUNCTIONS
  333.                 . \$WRAPPER_FUNCTIONS/ow.sh.fctn
  334.                 Ow
  335.                 REMOTE=yes
  336.         export PATH DISPLAY OPENWINHOME LD_LIBRARY_PATH TERM REMOTE
  337.         $REMSPECIAL
  338.         \$OPENWINHOME/bin/cmdtool -i $REMCOMMAND ${1+$@}
  339.                 read abc" | \
  340.             exec $RSH $REMHOST sh
  341.     else
  342.         /bin/echo "DISPLAY=$display_host$display_num
  343.         TERM=$TERM
  344.         PATH=$REMPATH
  345.                 REMOTE=yes
  346.         export PATH DISPLAY OPENWINHOME LD_LIBRARY_PATH TERM REMOTE
  347.         $REMSPECIAL
  348.         $REMCOMMAND ${1+$@}" | exec $RSH $REMHOST sh
  349.     fi
  350.         exit
  351.        else
  352.         /bin/echo "
  353.     $whoami is not able to log directly into $REMHOST. This may be
  354.     because: $REMHOST is down, $REMHOST does not have an account for
  355.     $whoami, or $REMHOST's /etc/hosts.equiv file does not permit
  356.     direct logins from $hostname.
  357.  
  358.     Please try later or set REMHOST to a remote server that is
  359.     accessible.
  360. "
  361.         exit
  362.       fi
  363.      elif [ -z "$REMHOST" ]; then
  364.         
  365.       /bin/echo "
  366.     A Solaris 2.x version of $cmdname is not yet available on x86
  367.     machines. 
  368.  
  369.     To display $cmdname on $hostname, it is recommended that you use
  370.     the following procedure: 
  371.  
  372.     1. Set an environmental variable \"REMHOST\" to the name of a known
  373.        xhost server. For example:
  374.  
  375.         setenv REMHOST <some_xhost_server> (csh users)
  376.  
  377.                 or
  378.  
  379.         REMHOST=<some_xhost_server>; export REMHOST (sh users)
  380.  
  381.                 or
  382.  
  383.         export REMHOST=<some_xhost_server> (ksh users)
  384.                  
  385.        You must be able to log directly into the machine
  386.        you have REMHOST set to. In addition The machine
  387.        must have $DIST_HOME and in some cases, your home
  388.        directory mounted.
  389.  
  390.        Please do not set REMHOST to a $DIST_HOME server!!!
  391.  
  392.     2. After setting REMHOST, execute the $cmdname command.
  393.  
  394.         This procedure only works for OpenWindows based tools. 
  395.         It will not work for SunView based tools.
  396.  
  397.     Thank-you for your cooperation
  398.     " | more
  399.        exit
  400.     
  401.    fi
  402. }
  403.  
  404. Remhost "$@"
  405. fi
  406. ##
  407.  
  408. SAVE_LD_LIB=${LD_LIBRARY_PATH:-}
  409. LD_LIBRARY_PATH=${OPENWINHOME}/lib:$CAM_HOME/${major_os}lib.${arch}${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}
  410.  
  411. NEWS=
  412. if [ $major_os = "5" ]; then
  413.   if [ `/bin/expr $os \< "5.3"` -eq 1 ] ; then
  414.     NEWS=".news"
  415.   fi
  416. fi
  417. ##
  418. # Local Configuration Block
  419. ##
  420.  
  421.  
  422. ##
  423. # Application Execution Block
  424. ##
  425. PATH=$SAVED_PATH; export PATH
  426.  
  427. exec $command $cmdname ${1+"$@"} $opt
  428.